using System;
using System.Collections;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class ValidatableRuleAttributeTest
    {

        [Test]
        public void CheckValues()
        {
            var ruleAttribute = new ValidatableRuleAttribute {UseMemberErrorMessages = true};


            var propertyRule = (ValidatableRule)ruleAttribute.CreateRule(new MockPropertyDescriptor<IValidatable>("foo"));
            var parameterRule = (ValidatableRule)ruleAttribute.CreateRule(new MockParameterDescriptor<IValidatable>("foo"));

            Assert.IsNotNull(propertyRule);
            Assert.IsTrue(propertyRule.UseMemberErrorMessages);

            Assert.IsNotNull(parameterRule);
            Assert.IsTrue(parameterRule.UseMemberErrorMessages);
        }


        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void CheckPropertyRuleErrorMessageUseMemberErrorMessages()
        {
            var ruleAttribute = new ValidatableRuleAttribute
                                                         {
                                                             ErrorMessage = "foo",
                                                             UseMemberErrorMessages = true
                                                         };
            ruleAttribute.CreateRule(new MockPropertyDescriptor<IValidatable>("foo"));
        }


        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void CheckParameterRuleErrorMessageUseMemberErrorMessages()
        {
            var ruleAttribute = new ValidatableRuleAttribute
                                                         {
                                                             ErrorMessage = "foo",
                                                             UseMemberErrorMessages = true
                                                         };
            ruleAttribute.CreateRule(new MockParameterDescriptor<IValidatable>("foo"));
        }


        [Test]
        public void CallAttributeTester()
        {
            AttributeTester.CheckDefaultValues<IList>(new ValidatableRuleAttribute(), true, true);
            AttributeTester.CheckNonDefaultValues<IList>(new ValidatableRuleAttribute(), true, true);
        }

    }
}